package io.unicorn.modules.water.controller;

import java.util.Arrays;
import java.util.Map;

import io.unicorn.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.unicorn.modules.water.entity.TCityInfoEntity;
import io.unicorn.modules.water.service.TCityInfoService;
import io.unicorn.common.utils.PageUtils;
import io.unicorn.common.utils.R;



/**
 * ${comments}
 *
 * @author LNCG
 * @email LNCG@USTL.EDU.CN
 * @date 2021-05-03 08:18:00
 */
@RestController
@RequestMapping("water/tcityinfo")
public class TCityInfoController {
    @Autowired
    private TCityInfoService tCityInfoService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("water:tcityinfo:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = tCityInfoService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{cityId}")
    @RequiresPermissions("water:tcityinfo:info")
    public R info(@PathVariable("cityId") String cityId){
        TCityInfoEntity tCityInfo = tCityInfoService.getById(cityId);

        return R.ok().put("tCityInfo", tCityInfo);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("water:tcityinfo:save")
    public R save(@RequestBody TCityInfoEntity tCityInfo){
        tCityInfoService.save(tCityInfo);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("water:tcityinfo:update")
    public R update(@RequestBody TCityInfoEntity tCityInfo){
        ValidatorUtils.validateEntity(tCityInfo);
        tCityInfoService.updateById(tCityInfo);
        
        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("water:tcityinfo:delete")
    public R delete(@RequestBody String[] cityIds){
        tCityInfoService.removeByIds(Arrays.asList(cityIds));

        return R.ok();
    }

}
